package com.struts.action;

import com.opensymphony.xwork2.ActionSupport;

public class ValidateAction extends ActionSupport{
	
	private String username ;
	private String password ;
	public String getUsername() {
		return username;
	}
	public void setUsername(String username) {
		this.username = username;
	}
	public String getPassword() {
		return password;
	}
	public void setPassword(String password) {
		this.password = password;
	}
	
	public String testValidate(){
		return SUCCESS;
	}
	
	@Override
	public void validate() {
		if("".equals(this.getUsername())||"".equals(this.getPassword())){
			this.addActionError("用户名或者密码不能为空");
			this.addActionMessage("用户名或者密码不能为空");
		}
		
		if("".equals(this.getUsername())){
			this.addFieldError("username","用户名不能为空");
		}
		if("".equals(this.getPassword())){
			this.addFieldError("password", "密码不能为空");
		}
		if(this.getPassword().length()<6){
			this.addFieldError("password","长度不能小于6");
		}
	}
	
}
